package noobteam.deartrainer.controller;

import noobteam.deartrainer.service.AdministratorInfoService;
import noobteam.deartrainer.service.UserInfoService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author 赵崇轩
 * @Date 2021/6/25 16:36
 * @Version 1.0
 */
@RestController
public class AdministratorInfoController {

    @Resource
    private AdministratorInfoService administratorInfoService;

    @RequestMapping("/admin_signIn")
    public String checkSignIn(@RequestParam Map<String,String> map){
        String msg = "登录成功";
        String name = map.get("adminName");
        String password = map.get("adminPassword");
        List<Map<String,Object>> list = administratorInfoService.getName();
        for(Map<String,Object> temp : list){
            if(temp.get("administratorName").equals(name)){
                Map<String, Object> adminPassWordByName = administratorInfoService.getUserPassWordByName(name);
                if (adminPassWordByName.get("administratorPassword").equals(password)){
                    return "登录成功";
                }
                else{
                    return "密码错误";
                }
            }
        }
        return "该管理员不存在，请检查";
    }

    @RequestMapping("/getAdminInfoByName")
    public Map<String, Object> findAdminInfoByName(@RequestParam Map<String, String> userName){
        String name = userName.get("adminName");
        Map<String, Object> map = administratorInfoService.getAdminInfoByName(name);
        return map;
    }
}
